<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="../include/tag.jsp" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>资金管理</title>
    <link rel="stylesheet" href="${ctx}/css/common/list.css">
    <link rel="stylesheet" href="${ctx}/css/common/table.css">
    <%@include file="../include/commonFile.jsp" %>
</head>
<body>

<!--头部-->
<%@include file="../include/header.jsp" %>
<div class="index-outside">
    <%@include file="../include/sidebar.jsp" %>
    <!--内容-->
    <section>
        <div class="section-main">
            <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                <ul class="layui-tab-title">
                    <li class="layui-this"><span class="title f18 ml5 mr5">全部资金</span></li>
                    <li><span class="title f18 ml5 mr5">众筹资金</span></li>
                    <%--<li><span class="title f18 ml5 mr5">活动资金</span></li>--%>
                </ul>
                <div class="member-index-top mt20">
                    <div class="top-left">
                        <div style="flex: 1;">
                            <div class="display-flex">
                                <div class="info-div" style="font-size:20px;">
                                    <span>&nbsp;&nbsp;&nbsp;累计资金： </span>
                                    <span><b class="active-red">
                                        <c:if test="${orderTotal > 0}">
							              <fmt:formatNumber pattern="#,###.##" value="${orderTotal}"/>
						                </c:if>
				                    	<c:if test="${orderTotal == 0.0}">
				                    		${orderTotal}
				                    	</c:if>
                                        </b>
                                    </span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-tab-content">
                    <div class="layui-tab-item layui-show">
                        <form class="layui-form" action="${ctx}/moneyManagement/allMoneyList.do" id="myForm"
                              method="post">
                            <input type="hidden" name="pageNo" id="pageNo"/>

                            <div class="f-search-bar">
                                <div class="search-container">
                                    <ul class="search-form-content">
                                        <li class="form-item"><label class="search-form-lable"></label>
                                            <div class="check-btn-inner">
                                                <a  href="javascript:void(0);"
                                                   onclick="setOpType($(this),0,'#myForm')" ${empty stype || stype == 0 ? 'class="active"' : ''}>收益明细</a>
<%--                                                <c:if test="${isBand}">--%>
                                                    <a href="javascript:void(0);"
                                                       onclick="setOpType($(this),1,'#myForm')" ${stype == 1 ? 'class="active"' : ''}>提现明细</a>
<%--                                                </c:if>--%>
                                                <input type="hidden" name="stype" value="${stype}"/>
                                            </div>
                                        </li>
                                    </ul>
                                    <c:if test="${stype == 0}">
                                        <ul class="search-form-content">
                                            <li class="form-item-inline"><label class="search-form-lable">订单名称</label>
                                                <div class="layui-input-inline">
                                                    <input type="text" name="title" class="layui-input"
                                                           value="${orderForm.title}" placeholder="请输入查询订单名称">
                                                </div>
                                            </li>
                                            <li class="form-item-inline"><label class="search-form-lable"
                                                                                style="margin-left: 14px;">下单者</label>
                                                <div class="layui-input-inline">
                                                    <input type="text" name="memberName" class="layui-input"
                                                           value="${input.memberName}" placeholder="请输入查询订单下单者">
                                                </div>
                                            </li>
                                            <li class="form-item-inline">
                                                <div class="sub-btns">
                                                    <a class="layui-btn layui-btn-danger" href="javascript:submitClk()">确定</a>
                                                    <a class="layui-btn layui-btn-normal" href="javascript:resetFunction('#myForm')">重置</a>
                                                </div>
                                            </li>
                                        </ul>
                                        <ul class="search-form-content">
                                            <li class="form-item"><label class="search-form-lable">订单类型</label>
                                                <div class="check-btn-inner">
                                                    <a id="all" href="javascript:void(0);"
                                                       onclick="setTimeType($(this),'','#myForm')" ${empty orderForm.type ? 'class="active"' : ''}>全部</a>
                                                    <c:forEach var="map" items="${orderTypes}">
                                                        <a href="javascript:void(0);"
                                                           onclick="setTimeType($(this),'${map.key}','#myForm')" ${orderForm.type == map.key ? 'class="active"' : ''}>${map.value}</a>
                                                    </c:forEach>
                                                    <input type="hidden" name="type" value="${orderForm.type}"/>
                                                </div>
                                            </li>
                                        </ul>
                                        <ul class="search-form-content">
                                            <li class="form-item"><label class="search-form-lable">下单时间</label>
                                                <div class="check-btn-inner" id="timeType">
                                                    <a href="javascript:void(0);"
                                                       onclick="setTimeType($(this),0,'#myForm')" ${empty input.timeType || input.timeType == 0 ? 'class="active"' : ''}>全部</a>
                                                    <a href="javascript:void(0);"
                                                       onclick="setTimeType($(this),4,'#myForm')" ${input.timeType == 4 ? 'class="active"' : ''}>昨天</a>
                                                    <a href="javascript:void(0);"
                                                       onclick="setTimeType($(this),1,'#myForm')" ${input.timeType == 1 ? 'class="active"' : ''}>今天</a>
                                                    <a href="javascript:void(0);"
                                                       onclick="setTimeType($(this),2,'#myForm')" ${input.timeType == 2 ? 'class="active"' : ''}>本周内</a>
                                                    <a href="javascript:void(0);"
                                                       onclick="setTimeType($(this),3,'#myForm')" ${input.timeType == 3 ? 'class="active"' : ''}>本月内</a>
                                                    <input type="hidden" name="timeType" value="${input.timeType}"/>
                                                </div>
                                                <div class="layui-inline">
                                                    <div class="layui-input-inline">
                                                        <input class="layui-input" type="text" name="createStart"
                                                               value="${input.createStart}" placeholder="开始日">
                                                    </div>
                                                    -
                                                    <div class="layui-input-inline">
                                                        <input class="layui-input" type="text" name="createEnd"
                                                               value="${input.createEnd}" placeholder="截止日">
                                                    </div>
                                                </div>
                                            </li>
                                            <div class="l" style="width: 30%">
                                                <li style="cursor: pointer;" class="r"><a
                                                        class="layui-btn layui-btn-danger layui-btn-sm" href="javascript:txz.expireCheck('', function() { exportExcelData() })">导出EXCEL</a>
                                                </li>
                                            </div>
                                        </ul>
                                    </c:if>
                                    <c:if test="${stype == 1}">
                                        <ul class="search-form-content">
                                            <div class="l" style="width: 50%">
                                                <li class="f16">提现总金额
                                                    <span class="red">
											<c:if test="${withdrawalTotal > 0}">
                                                <fmt:formatNumber pattern="#,###.##" value="${withdrawalTotal}"/>
                                            </c:if>
											<c:if test="${withdrawalTotal == 0.0}">
                                                ${withdrawalTotal}
                                            </c:if>
										</span> 元（包含已扣除0.6%的微信商户提现手续费）
                                                </li>
                                            </div>

                                            <p class="cl"></p>
                                        </ul>
                                    </c:if>
                                </div>
                            </div>
                        </form>
                        <div class="my-act-list-content">
                            <div class="cl">
                                <c:if test="${stype == 0}">
                                    <table class="layui-table">
                                        <colgroup>
                                            <col>
                                            <col>
                                            <col>
                                            <col width="150px">
                                            <col width="150px">
                                            <col width="150px">
                                            <col width="150px">
                                            <col width="150px">
                                            <col width="110px">
                                        </colgroup>
                                        <thead>
                                        <tr>
                                            <th>订单名称</th>
                                            <th>下单者</th>
                                            <th>商户</th>
                                            <th>订单类型</th>
                                            <th>金额</th>
                                            <th>订单状态</th>
                                            <th>支付方式</th>
                                            <th>下单时间</th>
                                            <th>操作</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <c:if test="${page.totalCount == 0}">
                                            <tr>
                                                <td colspan="9">
                                                    <div class="f16 tc">还没有收益记录</div>
                                                </td>
                                            </tr>
                                        </c:if>
                                        <c:forEach var="orderForm" items="${orderForms}">
                                            <tr>
                                                <td title="${orderForm.title}"
                                                    onclick="openDialogNoButton('订单详情','${ctx}/order/order/orderInfo.do?id=${orderForm.id}','450px','570px')">
                                                    <div class="member-name ellipsis-1 blue"
                                                         style="cursor: pointer">${orderForm.title}</div>
                                                </td>
                                                <td class="table-member"
                                                    onclick="openDialogShow('用户名片','${ctx}/system/member/memberView.do?id=${orderForm.memberId}','400px','470px')">
                                                    <div class="member-cell">
                                                        <div class="member-logo common-img">
                                                            <img src="<c:if test="${ orderForm.member.logo!= null}">${orderForm.member.logo}?imageMogr2/auto-orient/crop/126x126</c:if>"
                                                                 alt="" onerror="txz.errImg(this)"
                                                                 onload="txz.imgLoad(this)">
                                                        </div>
                                                        <div class="member-name ellipsis-1">
                                                            <a class="blue" title="${orderForm.member.realname}"
                                                               style="cursor: pointer;">${orderForm.member.realname}</a>
                                                        </div>
                                                    </div>
                                                </td>
                                                <td>${orderForm.merchantName}</td>
                                                <td>${orderForm.typeName}</td>
                                                <td>￥${orderForm.payment}</td>
                                                <td>
                                                    <c:choose>
                                                        <c:when test="${orderForm.status == 0}">
                                                            <span>审核中</span>
                                                        </c:when>
                                                        <c:when test="${orderForm.status == 1}">
                                                            <span>待支付</span>
                                                        </c:when>
                                                        <c:when test="${orderForm.status == 2}">
                                                            <span style="color: red;">已支付</span>
                                                        </c:when>
                                                        <c:when test="${orderForm.status == 3}">
                                                            <span>其它</span>
                                                        </c:when>
                                                        <c:when test="${orderForm.status == 4}">
                                                            <span>已退款</span>
                                                        </c:when>
                                                    </c:choose>
                                                </td>
                                                <td>
                                                    <div>
                                                        <c:choose>
                                                            <c:when test="${orderForm.paymentWay == 1}">微信</c:when>
                                                            <c:when test="${orderForm.paymentWay == 0}">支付宝</c:when>
                                                        </c:choose>
                                                    </div>
                                                </td>
                                                <td><fmt:formatDate value="${orderForm.updateDate}"
                                                                    pattern="yyyy-MM-dd HH:mm"/></td>
                                                <td>
                                                    <c:if test="${orderForm.type == 3 || orderForm.type == 7}"><a
                                                            href="javascript:showAuthor('${orderForm.id}')" class="red">查看众筹者</a></c:if>
                                                </td>
                                            </tr>
                                        </c:forEach>
                                        </tbody>
                                    </table>
                                </c:if>

                                <c:if test="${stype == 1}">
                                    <table class="layui-table">
                                        <colgroup>
                                            <col width="240px">
                                            <col width="240px">
                                            <col width="110px">
                                            <col width="110px">
                                            <col width="120px">
                                            <col width="120px">
                                            <col width="140px">
                                            <col width="110px">
                                        </colgroup>
                                        <thead>
                                        <tr>
                                            <th>提现账号</th>
                                            <th>开户行</th>
                                            <th>开户名</th>
                                            <th>提现金额</th>
                                            <th title="提现金额x(微信提现手续费(0.006)+平台提现手续费)">手续费<font style="color: red" size="5">*</font></th>
                                            <th>支付净额</th>
                                            <th>提现时间</th>
                                            <th>状态</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <c:if test="${page.totalCount == 0}">
                                            <tr>
                                                <td colspan="8">
                                                    <div class="f16 tc">还没有提现记录</div>
                                                </td>
                                            </tr>
                                        </c:if>
                                        <c:forEach var="withdrawal" items="${withdrawals}">
                                            <tr>
                                                <td>${withdrawal.accountNumber}</td>
                                                <td>${withdrawal.openedPlace}</td>
                                                <td>${withdrawal.name}</td>
                                                <td><fmt:formatNumber pattern="0.00" value="${withdrawal.payment}"/>元
                                                </td>
                                                <td><fmt:formatNumber pattern="0.00"
                                                                      value="${withdrawal.serviceFee}"/>元
                                                </td>
                                                <td><fmt:formatNumber pattern="0.00"
                                                                      value="${withdrawal.netAmount}"/>元
                                                </td>
                                                <td><fmt:formatDate value="${withdrawal.createDate}"
                                                                    pattern="yyyy-MM-dd HH:mm"/></td>
                                                <td title="${withdrawal.remarks}" >
                                                    <c:if test="${withdrawal.status == 1 or withdrawal.status == 4}">
                                                        <span>处理中</span>
                                                    </c:if>
                                                    <c:if test="${withdrawal.status == 2}">
                                                        <span style="color: green;" >已付款</span>
                                                    </c:if>
                                                    <c:if test="${withdrawal.status == 3}">
                                                        <span><a href="javascript:showAuthor1('${withdrawal.remarks}')" class="red">已拒绝</a> </span>
                                                    </c:if>
                                                </td>
                                            </tr>
                                        </c:forEach>
                                        </tbody>
                                    </table>
                                </c:if>
                                <div class="page-content">
                                    <div id="page_content" class="page-container"></div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-tab-item"></div>
                    <div class="layui-tab-item"></div>
                </div>
            </div>
        </div><!--底部-->
        <%@include file="../include/footer.jsp" %>
    </section>
    <div id="authorDialog">
        <table class="layui-table" lay-skin="line">
            <tbody>
            <tr>
                <td class="table-member">
                    <div class="member-cell">
                        <div class="member-logo"></div>
                        <div class="member-name ellipsis-1">
                            <a href="javascript:void(0);"></a>
                        </div>
                    </div>
                </td>
            </tr>
            </tbody>
        </table>
    </div>

    <div id="authorDialog1">
        <table class="layui-table" lay-skin="line">
            <tbody>
            <tr>
                <td class="table-member">
                    <div class="member-cell">
                        <div class="member-name ellipsis-1">

                        </div>
                    </div>
                </td>
            </tr>
            </tbody>
        </table>
    </div>
</div>

<script type="text/javascript" src="${ctx}/script/common/list.js"></script>
<script type="text/javascript">
    $(function () {

        txz.initHeader({
            nav: [{
                name: '资金管理',
                curr: true
            }]
        });


        layui.use([ 'element' ], function() {
            var element = layui.element;

            element.on('tab', function (data) {
                if (data.index == 0) {
                    location.href = "${ctx}/moneyManagement/allMoneyList.do";
                } else if(data.index == 1){
                    location.href = "${ctx}/moneyManagement/crowdFundingMoneyList.do";
                }/* else if (data.index == 2) {
                    //location.href = "${ctx}/order/order/tradeList.do";
                    location.href = "${ctx}/charge/package/packageMemberList.do";

                }*/
            });
        });

        //加载分页
        loadPageNew({
            elem: 'page_content',
            totalCount: '${page.totalCount}',
            limit: '${page.limit}',
            callback: submitClk,
            page: '${page.page}'
        });

        layui.use(['laydate'], function () {
            var laydate = layui.laydate;
            // 查询发布日期
            var start = {
                elem: 'input[name=createStart]'
            };

            var end = {
                elem: 'input[name=createEnd]'
            };
            laydate.render(start);
            laydate.render(end);
        });
    })

    function showAuthor(orderId) {
        var setPayIndex = layer.open({
            type: 1,
            area: '400px',
            title: '查看众筹者',
            content: $("#authorDialog"),
            btn: ['关闭'],
            success: function () { // 弹出后回调
                $.get('${ctx}/crowdfund/project/getProjectAuthorByOrder.do', {'orderId': orderId}, function (res) {
                    if (res.success) {
                        var logo = res.data.authorLogo;
                        if (logo) {
                            $("#authorDialog").find(".member-logo").css('background-image', 'url(' + logo + '?imageMogr2/auto-orient/crop/126x126)');
                        } else {
                            $("#authorDialog").find(".member-logo").css('background-image', 'url(${ctx}/image/def_user_logo.png)');
                        }
                        $("#authorDialog").find(".member-name a").text(res.data.authorName);
                    } else {
                        util.layerMsgError("查看众筹者失败");
                    }
                })
            },
            end: function () { // 销毁后回调
                $("#authorDialog").find(".member-logo").css('background-image', '');
                $("#authorDialog").find(".member-name a").text('');
            },
            yes: function () { // 确定按钮
                layer.close(setPayIndex);
            }
        });
    }

    function showAuthor1(remarks) {
        var setPayIndex = layer.open({
            type: 1,
            area: '400px',
            title: '查看备注',
            content: $("#authorDialog1"),
            btn: ['关闭'],
            success: function () { // 弹出后回调
                if(remarks!=null && remarks.length>0){
                    $("#authorDialog1").find(".member-name").text(remarks);
                }else{
                    util.layerMsgError("暂无备注");
                }
            },
            end: function () { // 销毁后回调
                $("#authorDialog1").find(".member-name").text('');
            },
            yes: function () { // 确定按钮
                layer.close(setPayIndex);
            }
        });
    }

    function setOpType(obj, value, myForm) {
        $(obj).parent(".check-btn-inner").find("a").removeClass("active");
        $(obj).addClass("active");
        $(obj).parent(".check-btn-inner").find("[type=hidden]").val(value);
        $(myForm).submit();
    }

    function submitClk(){
        var paramsArray = $("#myForm").serializeArray();
        var params = new Array();
        $.each(paramsArray, function (i, param) {
            if(param.value != ""){
                params.push(param.value);
            }
        });

        if(params.length > 2) {
            $("#flag").val(true);
        } else if(params.length == 2) {
            $("#flag").val(false);
        }
        $("#myForm").submit();
    }

    function exportExcelData() {
        layer.confirm('确认要导出Excel吗?', {
            icon: 3,
            title: '系统提示'
        }, function (index) {
            var url = "${ctx}/wallet/exportOrder.do";

            //loading层
            var loadIndex = layer.load(1, {
                shade: [0.1, '#fff'] //0.1透明度的白色背景
            });
            $.post(url, $("#myForm").serialize(), function (res) {
                top.layer.close(loadIndex);
                if (res.success) {
                    window.location.href = res.data;
                } else {
                    util.layerMsgError(res.description)
                }
            });
            top.layer.close(index);
        });
    }

</script>
</body>
</html>